<template>
  <section>
    <!--工具条-->
    <el-col :span="24" class="toolbar" style="padding-bottom: 0px;">
      <el-form :inline="true" :model="filters">
        <el-form-item>
          <el-input v-model="filters.keyword" placeholder="关键字"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" v-on:click="search">查询</el-button>
        </el-form-item>
      </el-form>
    </el-col>

    <!--列表-->
    <el-table :data="logs"  highlight-current-row v-loading="listLoading" @selection-change="selsChange" style="width: 100%;">
      <el-table-column type="selection" width="55">
      </el-table-column>
      <el-table-column type="index" width="60">
      </el-table-column>
      <el-table-column prop="product.name" label="服务名称" width="200" >
      </el-table-column>
      <el-table-column prop="state" label="状态" width="400" >
        <template scope="scope">
          <span style="color: red" v-if="scope.row.state === 0">失败</span>
          <span style="color: green" v-else-if="scope.row.state === 1">成功</span>
        </template>
      </el-table-column>
      <el-table-column prop="audit.username" label="审核员" width="300" >
        <template scope="scope">
          <span v-if="scope.row.auditId === null">系统审核</span>
          <span v-if="scope.row.auditId !== null">{{scope.row.audit.username}}</span>
        </template>
      </el-table-column>
      <el-table-column prop="auditTime" label="审核时间" width="200" >
      </el-table-column>
      <el-table-column prop="note" label="备注" width="250" >
      </el-table-column>
      <el-table-column label="操作" >
        <template scope="scope">
          <el-button type="danger" size="small" @click="handleDel(scope.$index, scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <!--工具条-->
    <el-col :span="24" class="toolbar">
      <el-button type="danger" @click="batchRemove" :disabled="this.sels.length===0">批量删除</el-button>
      <el-pagination layout="prev, pager, next" @current-change="handleCurrentChange"
                     :page-size="pageSize" :total="totals" :current-page="currentPage"
                     style="float:right;">
      </el-pagination>
    </el-col>

  </section>
</template>

<script>

export default {
  data() {
    return {
      filters: {
        keyword: ''
      },
      logs: [],
      totals: 0,
      pageSize:10,
      currentPage:1,
      //page: 1,
      listLoading: false,
      sels: [],//列表选中列
    }
  },
  methods: {
    // 获取类型
    search(){
      this.currentPage = 1;
      this.getLogs();
    },
    handleCurrentChange(val) {
      this.currentPage = val;
      this.getLogs();
    },
    //获取员工列表
    getLogs() {
      let para = {
        pageSize: this.pageSize,
        currentPage: this.currentPage,
        keyword: this.filters.keyword
      };
      this.listLoading = true;
      //NProgress.start();
      // 发送axios请求获取后端数据
      this.$http.post("/productOnsaleAuditLog/list",para)
          .then(result=>{
            // 关闭列表忙等
            this.listLoading = false;
            // 请求成功
            this.logs = result.data.rows;
            this.totals = result.data.totals;
            console.log(this.logs)
          })
          .catch(result=>{
            // 请求失败
            this.$message({
              message: '请求失败',
              type: 'error'
            });
          })
    },
    //删除
    handleDel: function (index, row) {
      this.$confirm('确认删除该记录吗?', '提示', {
        type: 'warning'
      }).then(() => {
        // 忙等
        this.listLoading = true;
        this.$http.delete("/productOnsaleAuditLog/"+row.id)
            .then(result=>{
              // 请求发送成功
              this.listLoading = false;
              if (result.data.success){
                this.$message({
                  message: result.data.msg,
                  type: 'success'
                });
                this.currentPage = 1;
                this.getLogs();
              }else {
                this.$message({
                  message: result.data.msg,
                  type: 'error'
                });
              }
            })
            .catch(result=>{
              // 请求失败
              this.listLoading = false;
              this.$message({
                message: "网络异常",
                type: 'error'
              });
            })
      }).catch(() => {

      });
    },
    selsChange: function (sels) {
      this.sels = sels;
    },
    //批量删除
    batchRemove: function () {
      var ids = this.sels.map(item => item.id);
      this.$confirm('确认删除选中记录吗？', '提示', {
        type: 'warning'
      }).then(() => {
        this.listLoading = true;
        //NProgress.start();
        let para = { ids: ids };
        this.$http.patch("/productOnsaleAuditLog",ids)
            .then(result =>{
              // 请求发送成功
              if(result.data.success){
                this.$message({
                  message: result.data.msg,
                  type: 'success'
                });
                this.currentPage = 1;
                this.getLogs();
              }else {
                this.$message({
                  message: result.data.msg,
                  type: 'error'
                });
              }
            })
            .catch(result =>{
              // 请求发送失败
              this.$message({
                message: "网络异常",
                type: 'error'
              });
            });
      }).catch(() => {

      });
    }
  },
  mounted() {
    this.getLogs();
  }
}

</script>

<style scoped>

</style>